home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / MATH1 / SORT-B.LIB < prev    next >
Text File  |  1985-04-03  |  640b  |  34 lines

  1.  
  2.  
  3. { --> 176}
  4. procedure {bubble} sort(var a: ary; n: integer);
  5. { adapted from 'Introduction to PASCAL',
  6.     R.Zaks, Sybex, 1980 }
  7.  
  8. var    no_change    : boolean;
  9.     j        : integer;
  10.  
  11. procedure swap(p,q: real);
  12. var    hold    : real;
  13. begin
  14.   hold:=p;
  15.   p:=q;
  16.   q:=hold
  17. end;        { swap }
  18.  
  19. begin        { procedure sort }
  20.   repeat
  21.     no_change:=true;
  22.     for j:=1 to n-1 do
  23.       begin
  24.     if a[j]>a[j+1] then
  25.       begin
  26.         swap(a[j],a[j+1]);
  27.         no_change:=false
  28.       end
  29.     end    { for }
  30.   until no_change
  31. end;    { procedure sort }
  32.  
  33.  
  34.